<!DOCTYPE html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <title>地理定位</title>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=l7XwoPUhos8PewiNrhTrBvcnLDNUrhKe"></script>
    <style type="text/css">
        body,
        html,
        #container {
            width: 100%;
            height: 100%;
            overflow: hidden;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
</head>

<body>
    <div id="container"></div>
</body>

</html>
<script type="text/javascript">
    window.navigator.geolocation.getCurrentPosition(function(pos) {
        let lat = pos.coords.latitude
        let lon = pos.coords.longitude
        var map = new BMap.Map("container");
        map.addControl(new BMap.ScaleControl()); 
        map.addControl(new BMap.NavigationControl());
        // 创建地图实例  
        var point = new BMap.Point(lon, lat);
        // 创建点坐标  
        map.centerAndZoom(point, 15);
        // 初始化地图，设置中心点坐标和地图级别  
        var marker = new BMap.Marker(point); // 创建标注    
        map.addOverlay(marker);
    }, function(err) {
        console.log(err)
    })
</script>